/**
 * Copyright (c) 2017-2017 All Rights Reserved.
 */
package com.zbest.zpay.paycore.biz.action.paytool;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zbest.zpay.paycore.dal.dao.PaySubInfoDAO;
import com.zbest.zpay.paycore.dal.model.FluxInfoDO;
import com.zbest.zpay.paycore.helper.PaySubInfoStatusManager;
import com.zbest.zpay.paycore.model.PaySubInfoStatus;
import com.zbest.zpay.service.exchange.model.FluxInfoStatus;
import com.zbest.zpay.service.exchange.model.FluxKeyEnum;
import com.zbest.zpay.shared.process.BaseAction;
import com.zbest.zpay.shared.process.ProcessResult;

/**
 * 
 *
 * @author Administrator
 * @version $Id: HandlePaySubInfoAction.java, v 0.1 2017-4-24 下午11:39:34 Administrator Exp $
 */
@Service("handlePaySubInfoAction")
public class HandlePaySubInfoAction extends BaseAction {

    @Resource
    private PaySubInfoDAO           paySubInfoDAO;

    @Resource
    private PaySubInfoStatusManager paySubInfoStatusManager;

    /** 
     * @see com.zbest.zpay.shared.process.BaseAction#perform(com.zbest.zpay.shared.process.ProcessResult)
     */
    @Override
    public void perform(ProcessResult processResponse) {

        String fluxStatus = getValue(FluxKeyEnum.FLUX_STATUS.getCode());

        //处理支付子单，到这一步说明账户支付已经成功
        FluxInfoDO fluxInfoDO = getValue(FluxKeyEnum.FLUX_INFO_DO.getCode());
        PaySubInfoStatus paySubInfoStatus = null;
        if (fluxStatus.equals(FluxInfoStatus.SUCCESS.getCode())) {
            paySubInfoStatus = PaySubInfoStatus.SUCCESS;
        } else if (fluxStatus.equals(FluxInfoStatus.FAIL.getCode())) {
            paySubInfoStatus = PaySubInfoStatus.FAIL;
        } else {
            throw new UnsupportedOperationException();
        }

        paySubInfoStatusManager.statusCheck(PaySubInfoStatus.PROCESS.getCode(),
            paySubInfoStatus.getCode());
        paySubInfoDAO.updateStatusAndInstSerialNo(fluxInfoDO.getPaySubInfoId(),
            fluxInfoDO.getInstSerialNo(), paySubInfoStatus.getCode(),
            PaySubInfoStatus.PROCESS.getCode());

    }

}
